package com.vteApp;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class PatientRegistrationActivity extends VTEAppActivity implements
		OnClickListener {

	public final String firstName = "fName";
	public final String gender = "gender";

	private Spinner genderSpinner;
	private Spinner weightSpinner;
	private EditText fNameEditText;
	private EditText lNameEditText;
	private EditText ageEditText;
	private EditText weightEditText;

	private Button nextButton;

	@Override
	protected void onStart() {
		super.onStart();
		setContentView(R.layout.patientregistration);

		fNameEditText = (EditText) findViewById(R.id.first_name_edit_text);
		lNameEditText = (EditText) findViewById(R.id.last_name_edit_text);
		ageEditText = (EditText) findViewById(R.id.age_edit_text);
		weightEditText = (EditText) findViewById(R.id.weight_edit_text);
		genderSpinner = (Spinner) findViewById(R.id.weight_spinner);

		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.gender_array,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		genderSpinner.setAdapter(adapter);

		adapter = ArrayAdapter
				.createFromResource(this, R.array.weight_measurment,
						android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		weightSpinner = (Spinner) findViewById(R.id.weight_spinner);
		weightSpinner.setAdapter(adapter);

		nextButton = (Button) findViewById(R.id.button_next);
		nextButton.setOnClickListener(this);

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

		fNameEditText.setText(getSavedPreferenceValue("fName"));
		lNameEditText.setText(getSavedPreferenceValue("lName"));
		ageEditText.setText(getSavedPreferenceValue("age"));
		weightEditText.setText(getSavedPreferenceValue("weight"));

	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();

		saveIntoSavedPreferences("gender", genderSpinner.getSelectedItem()
				.toString());
		saveIntoSavedPreferences("fName", fNameEditText.getText().toString());
		saveIntoSavedPreferences("lName", lNameEditText.getText().toString());
		saveIntoSavedPreferences("age", ageEditText.getText().toString());
		saveIntoSavedPreferences("weight", weightEditText.getText().toString());
	}

	@Override
	public void onClick(View v) {
		startActivity(new Intent().setClass(this,
				UserRegistrationActivity.class));
	}
}
